package Nonogram;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

/**
 * PanelClueCol
 * @author Rachel Wedewer,
 * Date Modified: 4/30/2014
 * 
 * An important component of the GUI view.java.  This Jpanel represents the column clues that 
 * the user uses to solve the puzzle.  The column clues are represented by pulling out all the
 * elements from the CluesArray colClues (from Data) by colClues[line] and putting each clue into
 * a JLabel and adding one cell to the column of this classes grid layout.  This grid layout is CxN 
 * (C is equal to the number of clues found in the column with the most individual clues; N is the 
 * board size). Column lines with less clues than C will have empty cells on GUI in their column. 
 * The font of the JLabel changes depending on what the size of the puzzle. Also depending on what
 * cell in the PanelPuzzleGrid class is hovered over will highlight the corresponding cell in this
 * class. 
 * 
 */
public class PanelClueCol extends JPanel{

	private static Color HIGHTLIGHT = new Color(162,220,218);//Color(red, green, blue);
	private Color panelColor;//Color(red, green, blue);
	
	private int boardsize;
	private CluesArray clues;
	private JPanel cells[];
	private int lineHightlight;
	
	public PanelClueCol(CluesArray rowClues) {
		this.boardsize = rowClues.getClues().length;
		this.clues = rowClues;
		this.setLayout(new GridLayout(1,boardsize,5,5));
		this.setBackground(Color.BLACK);
		this.cells = new JPanel[this.boardsize];
		lineHightlight = 0;
		updateGUIPuzzle();
	}
	
	//For when a new puzzle is selected
    public void updateGUIPuzzle(){
    	this.removeAll();
    	createGirdCells();    	
    }
    
    public void createGirdCells(){
    	String cluesForLine="";
    	
    	for(int y=0;y<boardsize; y++){
    		cells[y] =new JPanel();
    		cells[y].setLayout(new BoxLayout(cells[y], BoxLayout.PAGE_AXIS));
    		
			for(int x =0; x< clues.getClues()[y].length; x++){	
				cluesForLine= String.valueOf(clues.getClues()[y][x]);
				JLabel label =new JLabel(cluesForLine);	
				label=increaseFontSize(label);
	    		cells[y].add(label);
				}
    		this.add(cells[y]);
    		}
    	panelColor =cells[0].getBackground();
    	}
    
    //Used to better adapt to different size puzzles
    private JLabel increaseFontSize(JLabel label){
    	Font f;
    	if (boardsize > 25){
    		f = new Font("Dialog", Font.BOLD, 15);
    	}
    	else if (boardsize > 15){
    		f = new Font("Dialog", Font.BOLD, 20);
    	}
    	else if (boardsize > 10){
    		f = new Font("Dialog", Font.BOLD, 25);
    	}
    	else{
    		f = new Font("Dialog", Font.BOLD, 32);
    	}
    	label.setFont(f);
    	return label;
    }
    
    public void colorClue(int line){
    	if (line != lineHightlight){
    	cells[lineHightlight].setBackground(panelColor);
    	cells[line].setBackground(HIGHTLIGHT);
    	lineHightlight = line;}
    }
    
    //Important for size panels in view.
    public int getMaxLineClues(){
    	int max =0;
    	for(int y=0;y<boardsize; y++){
    		if (clues.getClues()[y].length> max){
    			max = clues.getClues()[y].length;
    		}
    	}
    	return max;
    }
}
